/*处理登录用户权限的页面*/
import request from '@/helpers/request'
import { JSEncrypt } from 'jsencrypt' //RSA加密传输
import querystring from 'querystring' //序列化请求参数
import { format } from 'util';
import { config } from '../../static/config'
let formatData = (data) => {
    return querystring.stringify(data)
}//序列化请求参数 封装函数

const URL = {
    getBlog: '/blog/findAllBlogAndCommit',
    saveBlog: '/blog/addBlog',
    findBlogByBlogId: "/blog/findBlogByBlogId",
    upImg: '/file/upImg',
    findBlogCommitByBlogId: '/blog/findBlogCommitByBlogId',
    addCommit: "/commit/addCommit",
    findBlogClass: "/blog/findBlogClass",
    findBlogByUsername: '/blog/findBlogByUsername',
    updateBlog: "/blog/updateBlog",
    addFabulous: "/blog/addFabulous",
    cancelFabulous: "/blog/cancelFabulous",
    addReadCount: "/blog/addReadCount",
    changeHeadImg: '/user/changeHeadImg',
    updatedUserInfo: '/user/updatedUserInfo',
    findAllBlogByclassName: '/blog/findAllBlogByclassName',
    findFabByUsername: '/blog/findFabByUsername',
    reviewCommit: '/commit/reviewCommit',
    searchBlogbyTitleAndBody: '/blog/searchBlogbyTitleAndBody',
    upload: '/file/upload',
    findNext: '/blog/findNext',
    findPre: '/blog/findPre',
    deleteCommit: '/commit/deleteCommit',
    deleteCommitReview: "/commit/deleteCommitReview",
    addCollect: '/blog/addCollect',
    cancelCollect: '/blog/cancelCollect',
    findCollectAndFab: '/blog/findCollectAndFab',
    findCollectByUserName: '/blog/findCollectByUserName',
    deleteBlog: '/blog/deleteBlog',
    deleteBlogClass: '/blog/deleteBlogClass',
    addBlogClass: '/blog/addBlogClass'
}

export default {
    getBlog({ page, row }) {
        return request(URL.getBlog, 'get', { page, row }, { isToken: false })
    },
    findAllBlogByclassName({ className, page, row }) {
        return request(URL.findAllBlogByclassName, 'get', { className, page, row }, { isToken: false })
    },
    saveBlog(name, title, body, className, bgImg, upFileUrl, isTop, showIndex) {
        return request(URL.saveBlog, 'post', formatData({ name, title, body, className, bgImg, upFileUrl, isTop, showIndex }), { showProgress: false })
    },
    findBlogByBlogId(blogId) {
        return request(URL.findBlogByBlogId, 'get', { blogId }, { isToken: false })
    },
    upImg(imgData) {
        return request(URL.upImg, 'post', imgData, { showProgress: false, uploadModel: true, isToken: false })
    },
    findBlogCommitByBlogId(blogId) {
        return request(URL.findBlogCommitByBlogId, 'get', { blogId }, { showProgress: false, isToken: false })
    },
    addCommit(commitName, blogId, commitBody, avatar, date, mail, href) {
        return request(URL.addCommit, 'post', formatData({ commitName, blogId, commitBody, avatar, date, mail, href }), { showProgress: false })
    },
    reviewCommit(commitId, commitBody, toUser, fromUser, date, href) {
        return request(URL.reviewCommit, 'post', formatData({ commitId, commitBody, toUser, fromUser, date, href }), { showProgress: false })
    },
    findBlogClass() {
        return request(URL.findBlogClass, 'get')
    },
    findBlogByUsername(userName) {
        return request(URL.findBlogByUsername, 'get', userName)
    },
    updateBlog(title, body, className, blogId, update_time, bgImg, upFileUrl, isTop, showIndex) {
        return request(URL.updateBlog, 'post', formatData({ title, body, className, blogId, update_time, bgImg, upFileUrl, isTop, showIndex }))
    },
    addFabulous(userName, blogId) {
        return request(URL.addFabulous, 'post', formatData({ userName, blogId }), { showProgress: false })
    },
    cancelFabulous(userName, blogId) {
        return request(URL.cancelFabulous, 'post', formatData({ userName, blogId }), { showProgress: false })
    },
    addReadCount(blogId) {
        return request(URL.addReadCount, 'post', formatData({ blogId }))
    },
    changeHeadImg(headImg, userName, password) {
        return request(URL.changeHeadImg, 'post', formatData({ headImg, userName, password }))
    },
    updatedUserInfo(nickName, info, sex, name, password) {
        return request(URL.updatedUserInfo, 'post', formatData({ nickName, info, sex, name, password }))
    },
    findFabByUsername(userName) {
        return request(URL.findFabByUsername, 'get', userName)
    },
    searchBlogbyTitleAndBody(text, page, row) {
        return request(URL.searchBlogbyTitleAndBody, 'get', { text, page, row }, { showProgress: false, isToken: false })
    },
    upload() {
        return `${config.url.baseUrl}/file/upload`
    },
    upImgAvatar() {
        return `${config.url.baseUrl}/file/upImg`
    },
    findNext(blogId) {
        return request(URL.findNext, 'get', { blogId }, { showProgress: false, isToken: false })
    },
    findPre(blogId) {
        return request(URL.findPre, 'get', { blogId }, { showProgress: false, isToken: false })
    },
    deleteCommit(id) {
        return request(URL.deleteCommit, 'delete', { id }, { showProgress: false })
    },
    deleteCommitReview(id) {
        return request(URL.deleteCommitReview, 'delete', { id }, { showProgress: false })
    },
    addCollect(userName, blogId) {
        return request(URL.addCollect, 'post', formatData({ userName, blogId }), { showProgress: false })
    },
    cancelCollect(userName, blogId) {
        return request(URL.cancelCollect, 'post', formatData({ userName, blogId }), { showProgress: false })
    },
    findCollectAndFab(userName, blogId) {
        return request(URL.findCollectAndFab, 'post', formatData({ userName, blogId }), { showProgress: false, isToken: false })
    },
    findCollectByUserName(userName) {
        return request(URL.findCollectByUserName, 'get', { userName }, { showProgress: false })
    },
    deleteBlog(blogId) {
        return request(URL.deleteBlog, 'delete', { blogId }, { showProgress: false })
    },
    deleteBlogClass(className) {
        return request(URL.deleteBlogClass, 'delete', { className }, { showProgress: false })
    },
    addBlogClass(className) {
        return request(URL.addBlogClass, 'post', { className }, { showProgress: false })
    }
}